import { prisma } from "@/prisma";
import type { Comment } from "@prisma/client";
import { cache } from "react";

export type CommentWithAuthor = Comment & {
  User: { name: string | null; image: string | null };
};

export const  fetchCommentsByPostId = cache(async (postId: string): Promise<CommentWithAuthor[]> => {
  return prisma.comment.findMany({
    where: { postId },
    include: {
      User: {
        select: {
          name: true,
          image: true,
        },
      },
    },
  }) as Promise<CommentWithAuthor[]>;
})